/**
 * Filename AdvertiseControllrt.java 2020年12月23日
 * Copyright © Ehome Co.Ltd. All Rgiths Reserved.
 *
 * @author wuyingchao
 */
package com.ehome.poct.terminal.controller;

import com.ehome.poct.base.api.dto.banner.BannerExposureDTO;
import com.ehome.poct.base.api.feign.BannerClient;
import com.ehome.poct.base.api.vo.banner.BannerVO;
import com.ehome.poct.terminal.service.FileUploadService;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.support.StandardMultipartHttpServletRequest;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * 广告轮播图controller
 *
 * @author muqiu
 * @date 2022/03/03 16:47
 **/
@Api(tags = "首页轮播图")
@ApiSupport(author = "muqiu")
@RequestMapping("/api/banner")
@RestController
public class BannerController {

    @Autowired
    private BannerClient bannerClient;
    @Autowired
    FileUploadService fileUploadService;

    /**
     * 获取用户轮播图列表
     *
     */
    @ApiOperation("获取用户轮播图列表")
    @ApiOperationSupport(author = "muqiu")
    @GetMapping("/list")
    public List<BannerVO> listByClinicId(Integer deviceType){
        return bannerClient.list(deviceType);
    }

    /**
     * 广告曝光数增加
     * @param dto
     */
    @ApiOperation("图片曝光数增加")
    @ApiOperationSupport(author = "muqiu")
    @PutMapping("/incrExposure")
    public void incrExposureById(@RequestBody @Valid BannerExposureDTO dto){

        bannerClient.incrExposureById(dto);
    }


    @ApiOperation("文件上传")
    @ApiOperationSupport(author ="gyl")
    @PostMapping(value="/fileUpload",  consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
    public String fileUpload(HttpServletRequest request){
        MultipartFile file = ((StandardMultipartHttpServletRequest)request).getMultiFileMap().getFirst("file");
        if (null == file || file.isEmpty()) {
          return  null;
        }
        return fileUploadService.uploadFile(file);
    }
}